package com.example.test.controller;

import com.example.test.bean.domain.UserAddress;
import com.example.test.common.ResponseHelper;
import com.example.test.service.UserAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/address")
@Validated
@Tag(name = "后台地址管理")
public class AdminAddressController {

	@Resource
	private UserAddressService userAddressService;

	@Operation(summary = "管理员查看所有用户的收货地址列表")
	@GetMapping("/list")
	public ResponseHelper<List<UserAddress>> getAddressList() {
		List<UserAddress> addressList = userAddressService.getAddressList();
		return ResponseHelper.genResponse(addressList);
	}

	@Operation(summary = "管理员删除指定用户的收货地址")
	@DeleteMapping("/delete")
	public ResponseHelper<?> deleteAddress(@RequestParam Integer id, @RequestParam Integer userId) {
		userAddressService.deleteAddress(id, userId);
		return ResponseHelper.genResponse();
	}
}
